
/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

import "babel-polyfill";

window.Vue = require('vue');

import WeVue from 'we-vue';
import 'we-vue/lib/style.css';
import router from './webapp/router';
import store from './webapp/store';

import { mapState } from 'vuex'

import App from './webapp/App.vue';

Vue.config.productionTip = false;
Vue.config.devtools = true;

Vue.use(WeVue);

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

const app = new Vue({
    el: '#app',
    render: h => h(App),
    router,
    store,
    data () {
        return {
            transitionName: 'slide-right'
        }
    },

    mounted () {

    },

    computed: {
        ...mapState({
            isLoading: state => state.isLoading
        })
    },

    methods: {
        success (msg) {
            WeVue.Toast(msg)
        },

        error (msg) {
            WeVue.Toast({
                message: msg,
                icon: 'warn'
            })
        },

        toast (msg) {
            WeVue.Toast({
                duration: 2000,
                message: msg,
                type: 'text'
            })
        },

        loading (msg) {
            WeVue.Indicator.open({
                text: msg,
                spinnerType: 'double-snake'
            });
        },

        closeLoading() {
            WeVue.Indicator.close();
        },

        topTips (msg, duration = 3000) {
            WeVue.TopTips({
                message: msg,
                duration: duration
            })
        },

        confirm (content, title, callback) {
            WeVue.Dialog.confirm(content, title, {
                cancelText: '取消',
                showCancelBtn: true
            }).then(action => {
                callback(action);
            })
        },

        modal (content, title, confirmText = '确定', callback) {
            WeVue.Dialog.alert(content, title, {
                cancelText: '取消',
                showCancelBtn: false,
                showConfirmBtn: true,
                confirmText: confirmText
            }).then(action => {
                callback(action);
            })
        }
    },

    watch: {
        '$route' (to, from) {
            this.transitionName = from.name === 'index' ? 'slide-left' : 'slide-right'
        }
    }
});
